package com.dq.controller.app.goods;

import com.dq.controller.in.goods.stock.StockChangeRecordQuery;
import com.dq.domain.goods.stock.StockChangeRecord;
import com.dq.exception.customException.AdminException;
import com.dq.service.AllService;
import com.dq.vo.ListDataVo;
import com.dq.vo.Vo;
import com.dq.vo.baseVo.VO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cf
 */
@RestController
@RequestMapping("/app/goods/stockChange/")
@Api(description = "库存变动记录管理")
public class AppStockChangeRecordController extends AllService {

    @PostMapping("list")
    @ApiOperation("库存变动记录列表")
    public Vo orgStockChangeList(@RequestBody StockChangeRecordQuery orgStockChangeQuery) throws AdminException {
        List<StockChangeRecord> stockChangeRecordList = orgStockChangeService.list(orgStockChangeQuery);

        return new ListDataVo((List<StockChangeRecord.Vo>) VO.toVOCollection(stockChangeRecordList), orgStockChangeService.count(orgStockChangeQuery));
    }

    /**
     * 添加 库存变动, 对应goods默认product
     * 同时修改对应商品库存
     */
    @PostMapping("add")
    @ApiOperation("添加库存变动-出入库添加")
    public Vo addOrgStockChange(@RequestBody StockChangeRecord stockChangeRecord) throws AdminException {
        stockChangeRecord = orgStockChangeService.addStockChangeRecord(stockChangeRecord);

        return new Vo(stockChangeRecord.toVO());
    }

}
